package com.bp.village.assets.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.bp.village.assets.domain.SelectOptionVo;
import com.bp.village.enums.*;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bp.common.annotation.Log;
import com.bp.common.core.controller.BaseController;
import com.bp.common.core.domain.AjaxResult;
import com.bp.common.enums.EnumBusinessType;
import com.bp.village.assets.domain.BizVillageAssetsBuilding;
import com.bp.village.assets.service.IBizVillageAssetsBuildingService;
import com.bp.common.utils.poi.ExcelUtil;
import com.bp.common.core.page.TableDataInfo;

/**
 * 村级房屋资产管理Controller
 * 
 * @author shaominjie
 * @date 2021-01-29
 */
@RestController
@RequestMapping("/village/building")
public class BizAssetsBuildingController extends BaseController {
    @Resource
    private IBizVillageAssetsBuildingService bizVillageAssetsBuildingService;

    /**
     * 查询村级房屋资产管理列表
     */
//    @PreAuthorize("@ss.hasPermi('village:building:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizVillageAssetsBuilding bizVillageAssetsBuilding) {
        startPage();
        List<BizVillageAssetsBuilding> list = bizVillageAssetsBuildingService.selectList(bizVillageAssetsBuilding);
        return getDataTable(list);
    }

    /**
     * 导出村级房屋资产管理列表
     */
//    @PreAuthorize("@ss.hasPermi('village:building:export')")
    @Log(title = "村级房屋资产管理", businessType = EnumBusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizVillageAssetsBuilding bizVillageAssetsBuilding) {
        List<BizVillageAssetsBuilding> list = bizVillageAssetsBuildingService.selectList(bizVillageAssetsBuilding);
        ExcelUtil<BizVillageAssetsBuilding> util = new ExcelUtil<BizVillageAssetsBuilding>(BizVillageAssetsBuilding.class);
        return util.exportExcel(list, "building");
    }

    /**
     * 获取村级房屋资产管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('village:building:query')")
    @GetMapping(value = "/{buildingId}")
    public AjaxResult getInfo(@PathVariable("buildingId") Long buildingId)
    {
        return AjaxResult.success(bizVillageAssetsBuildingService.selectById(buildingId));
    }

    /**
     * 新增村级房屋资产管理
     */
//    @PreAuthorize("@ss.hasPermi('village:building:add')")
    @Log(title = "村级房屋资产管理", businessType = EnumBusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizVillageAssetsBuilding bizVillageAssetsBuilding) {
        AjaxResult ajaxResult = toAjax(bizVillageAssetsBuildingService.insert(bizVillageAssetsBuilding));
        ajaxResult.put("building",bizVillageAssetsBuilding);
        return ajaxResult;
    }

    /**
     * 修改村级房屋资产管理
     */
//    @PreAuthorize("@ss.hasPermi('village:building:edit')")
    @Log(title = "村级房屋资产管理", businessType = EnumBusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizVillageAssetsBuilding bizVillageAssetsBuilding) {
        return toAjax(bizVillageAssetsBuildingService.update(bizVillageAssetsBuilding));
    }

    /**
     * 删除村级房屋资产管理
     */
//    @PreAuthorize("@ss.hasPermi('village:building:remove')")
    @Log(title = "村级房屋资产管理", businessType = EnumBusinessType.DELETE)
	@DeleteMapping("/{buildingIds}")
    public AjaxResult remove(@PathVariable Long[] buildingIds) {
        return toAjax(bizVillageAssetsBuildingService.deleteByIds(buildingIds));
    }

    @GetMapping("/selectOption")
    public AjaxResult selectOption(){
        AjaxResult ajax = AjaxResult.success();
        List<SelectOptionVo> voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsBuildingCategory.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("buildingCategory", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsBuildingSourceFrom.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("buildingSourceFrom", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsBuildingUseStatus.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }

        ajax.put("buildingUseStatus", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsOfficeBuildingType.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("officeBuildingType", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsSafeguardBuildingType.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("safeguardBuildingType", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsBuildingProofType.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("buildingProofType", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsNatureType.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("natureType", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumLandUseType.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("landUseType", voList);
        voList = new ArrayList<>();
        for (Map.Entry<Integer, String> map : EnumsBuildingProofType.MAP.entrySet()) {
            SelectOptionVo vo = new SelectOptionVo();
            vo.setKey(map.getKey());
            vo.setValue(map.getValue());
            voList.add(vo);
        }
        ajax.put("buildingUseType", voList);
        return ajax;
    }
}
